﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace POSPlus.PrintManager
{
	public abstract class DatabaseView
	{
		public DatabaseView(String connectionString)
		{
			ConnectionString = connectionString;
		}

		public String ConnectionString { get; private set; }

		public static T FromDB<T>(Object value)
		{
			//try
			//{
				return Convert.IsDBNull(value) || string.IsNullOrEmpty(value.ToString()) ? default(T) : (T)value;
			/*}
			catch (InvalidCastException ex)
			{
				MessageBox.Show(ex.Message + "\n\nT: " +  + "\nValue: " + value.ToString(),"Casting Error",
					MessageBoxButtons.OK, MessageBoxIcon.Error);
				return default(T);
			}*/
		}

		public class DatabaseViewNotInstantiatedException : Exception
		{
			private string _message;

			public override String Message { get { return _message; } }

			public DatabaseViewNotInstantiatedException(String message)
			{
				_message = message;
			}

			public override String ToString()
			{
				return Message;
			}
		}
	}
}
